<template>
  <div class="right-container">
    <h3>Right 组件 --- {{ count }}</h3>
    <button @click="add">+1</button>
    <p>{{ msgFromLeft }}</p>
  </div>
</template>

<script>
//1.导入 eventBus 模块
import bus from "./eventBus.js";

export default {
  data() {
    return {
      //子组件自己的数据，将来希望把count的值传给父组件
      count: 0,
      msgFromLeft: "",
    };
  },
  methods: {
    add() {
      this.count++;
      //把自增结果传给父组件
      this.$emit("numchange", this.count);
    },
  },
  created() {
    //2.给bus绑定自定义事件
    bus.$on("share", (val) => {
      this.msgFromLeft = val;
    });
  },
};
</script>

<style lang="less">
.right-container {
  padding: 0 20px 20px;
  background-color: lightskyblue;
  min-height: 250px;
  flex: 1;
}
</style>
